package com.aaa.controller;

import com.aaa.entity.Book;
import com.aaa.service.impl.BookServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("book")
public class BookController {
   @Resource
    BookServiceImpl bookService;

    @ResponseBody
    @RequestMapping("find")
    public Map<String, Object> find(Integer pageSize, Integer pageNum){
        Map<String, Object> map = new HashMap<>();
        List<Book> userList = bookService.find(pageSize, pageSize*pageNum );
        Integer TotalNum = bookService.findcount();
        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }


    @RequestMapping("add")
    public int add(Book book){
        return bookService.add(book);
    }

    @ResponseBody
    @RequestMapping("update")
    public int update(Book book){
        System.out.println(book.getAuthor());
        return bookService.update(book);
    }

    @RequestMapping("undercarriage")
    public int undercarriage(Integer id){
        return bookService.undercarriage(id);
    }

    @RequestMapping("find1")
     public List<Book> find1(){
        return bookService.find1();
     }
}
